<template>
  <div class="total">
     <img src="../../static/image/backgroud.jpg" class="background-img"/>
    <div class="right">
      <div class="titles">洗衣机后台管理系统</div>
      <el-form
        :model="ruleForm"
        status-icon
        :rules="rules"
        ref="ruleForm"
        class="demo-ruleForm form"
      >
        <el-form-item prop="phoneNum">
          <el-input
            type="text"
            v-model="ruleForm.phoneNum"
            autocomplete="off"
            placeholder="用户名"
          ></el-input>
        </el-form-item>
        <el-form-item prop="pass">
          <el-input
            type="password"
            v-model="ruleForm.pass"
            autocomplete="off"
            placeholder="密码"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            @click="submitForm('ruleForm')"
            class="submit"
            >登录</el-button
          >
          <!-- <el-button @click="resetForm('ruleForm')">重置</el-button> -->
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import http from '../api';
export default {
  data() {
    var validatephoneNum = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入用户名'));
      } else {
        if (this.ruleForm.checkPass !== '') {
          this.$refs.ruleForm.validateField('checkPass');
        }
        callback();
      }
    };
    var validatePass = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'));
      } else {
        if (this.ruleForm.pass !== '') {
          this.$refs.ruleForm.validateField('checkPass');
        }
        callback();
      }
    };

    return {
      ruleForm: {
        pass: '',
        phoneNum: '',
      },
      rules: {
        phoneNum: [{ validator: validatephoneNum, trigger: 'blur' }],
        pass: [{ validator: validatePass, trigger: 'blur' }],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          console.log(this.ruleForm.phoneNum);
          sessionStorage.setItem('user-name',this.ruleForm.phoneNum);
          http
            .userLogin({
              admin_name: this.ruleForm.phoneNum,
              admin_password: this.ruleForm.pass,
            })
            .then((r) => {
              if (r.data.code === 200) {
                 console.log(r);
                sessionStorage.setItem('user-id',r.data.data.admin_id);
                this.$router.push({
                  path: '/home/index',
                });
              }
             
            });
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
  },
};
</script>
<style scoped>
.background-img{
  width: 100%;
  height: 100%;
  opacity: 0.5;
}
.total {
  width: 100%;
  height: 600px;
  /* height: 100%; */
  /* background-color: #4543cb; */
  margin-top: 60px;
  position: relative;
}
.submit {
  width: 100%;
  height: 50px;
  background-color: #80D5DF;
  margin-top: 30px;
  border: none;
}
.img1 {
  width: 55px;
  height: 55px;
  border-radius: 50%;
}
.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
}
.name {
  border-left: 1px solid gainsboro;
  height: 100%;
  display: flex;
  flex: 2;
  align-items: center;
  justify-content: center;
}
.title {
  width: 80%;
  height: 70px;
  margin: auto;
  font-size: 30px;
  margin-top: 10px;
  display: flex;
  align-items: center;
}
.form {
  width: 85%;
  margin: auto;
  font-size: 18px;
  padding: 25px;
  position: relative;
  left: 0px;
  top: 40px;
}
.right {
  position: absolute;
  width: 22%;
  height: 380px;
  background-color: rgba(112, 112, 112, 0.3);
  left: 35%;
  top: 80px;
  padding: 30px;
  text-align: center;
}

.el-input >>> .el-input__inner {
  height: 50px;
}
.titles{
  font-size: 32px;
  font-weight: bolder;
  color: rgb(89, 90, 90);
  position: relative;
  left: 0px;
  top: 20px;
}
</style>